package com.cyl.manager.pms.controller;

import com.cyl.manager.pms.req.BrandQueryReq;
import com.cyl.manager.pms.req.BrandReq;
import com.cyl.manager.pms.resp.BrandResp;
import com.cyl.manager.pms.service.BrandService;
import com.sincere.common.annotation.Log;
import com.sincere.common.core.controller.BaseController;
import com.sincere.common.enums.BusinessType;
import com.sincere.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 品牌管理Controller
 * 
 * @author lsh
 * @date
 */
@Api("品牌管理接口列表")
@RestController
@RequestMapping("/pms/brand")
@RequiredArgsConstructor
public class BrandController extends BaseController {

    private final BrandService service;

    @ApiOperation("查询品牌管理列表")
    @PreAuthorize("@ss.hasPermi('pms:brand:list')")
    @PostMapping("/list")
    public ResponseEntity<Page<BrandResp>> list(@RequestBody BrandQueryReq query, Pageable page) {
        return ResponseEntity.ok(service.queryBrandByPage(query, page));
    }

    @ApiOperation("所有品牌管理列表")
    @PreAuthorize("@ss.hasPermi('pms:brand:list')")
    @PostMapping("/all")
    public ResponseEntity<List<BrandResp>> all() {
        return ResponseEntity.ok(service.queryAllBrand());
    }

    @ApiOperation("导出品牌管理列表")
    @PreAuthorize("@ss.hasPermi('pms:brand:export')")
    @Log(title = "品牌管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public ResponseEntity<String> export(BrandQueryReq query) {
        List<BrandResp> list = service.exportBrandList(query);
        ExcelUtil<BrandResp> util = new ExcelUtil<>(BrandResp.class);
        return ResponseEntity.ok(util.writeExcel(list, "品牌管理数据"));
    }

    @ApiOperation("获取品牌管理详细信息")
    @PreAuthorize("@ss.hasPermi('pms:brand:query')")
    @GetMapping(value = "/{id}")
    public ResponseEntity<BrandResp> getInfo(@PathVariable("id") Long id) {
        return ResponseEntity.ok(service.queryBrandDetail(id));
    }

    @ApiOperation("新增品牌管理")
    @PreAuthorize("@ss.hasPermi('pms:brand:add')")
    @Log(title = "品牌管理", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseEntity<Boolean> create(@RequestBody BrandReq req) {
        return ResponseEntity.ok(service.create(req));
    }

    @ApiOperation("修改品牌管理")
    @PreAuthorize("@ss.hasPermi('pms:brand:edit')")
    @Log(title = "品牌管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseEntity<Boolean> update(@RequestBody BrandReq req) {
        return ResponseEntity.ok(service.update(req));
    }

    @ApiOperation("删除品牌管理")
    @PreAuthorize("@ss.hasPermi('pms:brand:remove')")
    @Log(title = "品牌管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public ResponseEntity<Boolean> remove(@PathVariable Long id) {
        return ResponseEntity.ok(service.deleteById(id));
    }

}
